<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /* 原型链继承 */
        function Super() {
            this.property = "super";
        }
        function Sub() {
            this.property = "sub";
        }
        Super.prototype.showType = function () {
            return this.property;
        }
        Sub.prototype = new Super();
        let sub = new Sub();
        let superr = new Super();
        console.log(sub.showType());
        console.log(sub.__proto__.__proto__.__proto__ === Object.prototype);
        console.log(superr.__proto__.__proto__ === Object.prototype);
        console.log(sub.__proto__.constructor === Super);
        console.log(superr.__proto__.__proto__.constructor === Object);

        /* let superr = new Super();
        console.log(superr.showType.call(sub)); */


        /* 盗用构造函数"继承" */
        function Person(name, age) {
            this.name = name;
            this.age = age;
        }
        function Student(name, age, grade) {
            Person.call(this, name, age); 
            // == this.Person(name, age)  ==  this.name = name, this.age = age
            this.grade = grade;
        }
        let s1 = new Student("lili", 11, 11);
        console.log(s1);

        /* 组合继承 */
        function SuperType(name) {
            this.name = name;
        }
        SuperType.prototype.sayName = function(){
            console.log("I am " + this.name);
        }
        function SubType(name, age){
            SuperType.call(this, name); //继承属性
            this.age = age;
        }
        SubType.prototype = new SuperType(); //继承方法
        let subtype = new SubType("sub", 11);
        subtype.sayName();

    </script>
</body>

</html>